#include "Task.h"

DWORD WINAPI ThreadFunc(LPVOID lpParam)
{
	CTask* pTask = (CTask*)lpParam;

	pTask->OnStart();
	while ( pTask->m_bWorking )	pTask->Run();		
	pTask->OnStop();

	return 0;
}

void CTask::Start()
{
	m_bWorking = true;
	DWORD dwThreadId;
	HANDLE hThread = CreateThread(NULL,0,ThreadFunc,this,CREATE_SUSPENDED,&dwThreadId);
	ResumeThread(hThread);
	CloseHandle(hThread);
}

void CTask::Stop()
{
	m_bWorking = false;
}
